home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / shells / kiss-0.11 / kiss-0 / kiss / src / dotouch.c < prev    next >
C/C++ Source or Header  |  1995-03-23  |  708b  |  42 lines

  1. #include "kiss.h"
  2.  
  3. static int touchfile (char *name)
  4. {
  5.     struct stat
  6.     statbuf;
  7.     register int
  8.     handle;
  9.  
  10.     if (stat (name, &statbuf))
  11.     {
  12.     if ( (handle = open (name, O_RDWR | O_CREAT, CREATEFLAGS)) < 0)
  13.         return (warning ("can't create \"%s\"", name));
  14.     close (handle);
  15.     }
  16.     else
  17.     {
  18.     if (utime (name, NULL))
  19.         return (warning ("problem setting time for \"%s\"", name));
  20.     }
  21.  
  22.     return (0);
  23. }
  24.  
  25.  
  26. int dotouch (Stringstack s)
  27. {
  28.     register int
  29.     i,
  30.     ret = 0;
  31.     
  32.     if (s.nstr == 1 || getopt (s.nstr, s.str, "h") != -1)
  33.     error ("Bad commandline.\n"
  34.            "Usage: %s file(s)\n"
  35.            , progname);
  36.  
  37.     for (i = 0; i < s.nstr; i++)
  38.     ret += touchfile (s.str [i]);
  39.  
  40.     return (ret);
  41. }
  42.